#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<stack>
using namespace std;
string word[100];
int dp[100][100],sum[100],from[100];
int cost(int x,int y,int m)
{
    return m-(sum[y]-sum[x-1]+y-x);
}
int main()
{
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>word[i],sum[i]=sum[i-1]+word[i].length();
    memset(dp,0x3f,sizeof(dp));
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=j-1;k>=0;k--)
            {
                int c=cost(k+1,j,m);
                if(c<0) break;
                if(dp[i][j]>dp[i-1][k]+(int)pow(c,3));
                {
                    dp[i][j]=dp[i-1][k]+(int)pow(c,3);
                    from[j]=k;
                }
            }
        }
    }
    int ans=11111111;
    for(int i=1;i<=n;i++)
    {
        if(ans>dp[i][n])
        ans=dp[i][n];
    }
    cout<<ans<<endl;
    stack<int> put;
    for(int i=n;i;i=from[i])
    {
        put.push(i);
    }
    int cnt=1;
    while(!put.empty())
    {
        for(int i=cnt;i<=put.top();i++)
        cout<<word[i]<<" ";
        cout<<endl;
        cnt=put.top()+1;
        put.pop();
    }
}